//
//  CustomCellTableViewController.swift
//  MacStudy
//
//  Created by 30san on 2020/9/24.
//  Copyright © 2020 Dawninest. All rights reserved.
//

import Cocoa

class CustomCellTableViewController: NSViewController, NSTableViewDataSource, NSTableViewDelegate {

    @IBOutlet weak var topImageView: NSImageView!
    @IBOutlet weak var tableView: NSTableView!

    private let dataSources = [
        ["icon", "ss123s"],
        ["icon", "s1232ss"],
    ]
    
    override func viewDidLoad() {
        super.viewDidLoad()
        tableView.dataSource = self
        tableView.delegate = self
        topImageView.image = NSImage(named: "icon")
    }
    
    func numberOfRows(in tableView: NSTableView) -> Int {
        return dataSources.count
    }
    
    func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {
        let cell: CustomTableCellView = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier.init("CustomTableCellViewIden"), owner: nil) as! CustomTableCellView
        print("dataSources[row][0] = \(dataSources[row][0])")
        cell.imageView?.image = NSImage(named: dataSources[row][0])
        cell.contentLabel.stringValue = dataSources[row][1]
        return cell
    }
    
    func tableView(_ tableView: NSTableView, heightOfRow row: Int) -> CGFloat {
        return 200
    }
}
